import React, { useEffect } from 'react';
import { context } from './example';

export const TestB = () => {
  const [data, setData] = React.useState(context.getData());

  useEffect(() => {
    const unsubscribe = context.subscribe((newValue) => {
      setData(newValue);
    });

    return () => unsubscribe();
  }, []);

  return (
    <div>
      <h2>Component B (Consumer)</h2>
      <p>Current Data: {data}</p>
    </div>
  );
};
